#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*#include <bios.h>*/
#define ShowMsg(strerror)\
{\
printf("%s\n",strerror);\
}
struct PT_tag
{

};

#ifndef _BD_
#define _BD_
int biosdisk(int cmd, int drive, int head, int track, int sector,int nsects, void *buffer)
{
    return 0;
}
#endif
int WriteFile(char *filename,int head,int cy,int sec)
{
    char sztemp[512];
    int ireadnum;
    char c=0;
    FILE *f=fopen(filename,"rb+");
    if(f==NULL)
    {
        ShowMsg("fopen Error");
        return 0;
    }
    while(!feof((f)))
    {
        memset(sztemp,0,512);
        ireadnum=fread(sztemp,1,512,f);
        if(ireadnum<=0)
        {
            memset(sztemp,0xff,512);
        }

        if (biosdisk(3,0x80,head,cy,sec,1,sztemp)==0)
        {
            sec++;
        }
        else
        {
            cy++;
            sec=1;
            if(biosdisk(3,0x80,head,cy,sec,1,sztemp)==0)
            {
                sec++;
            }
            else
            {
                head++;
                cy=0;
                sec=1;
            }
        }
        if(ireadnum<=0)
        {
            break;
        }


    }
    fclose(f);
}
int main(int argc,char *argv[])
{
    char* szfilename;
    int ihead,icy,isec;
    sscanf(argv[2],"%d",&ihead);
    printf("%d\n",ihead);
    sscanf(argv[3],"%d",&icy);
    printf("%d\n",icy);
    sscanf(argv[4],"%d",&isec);
    printf("%d\n",isec);
    szfilename=argv[1];
    if(argv[1]==NULL ||argc<5)
    {
        ShowMsg("Arg Error");
        return 0;
    }
    WriteFile(szfilename,ihead,icy,isec);
    return 0;

}

